package com.wxy.student.controller;


import com.wxy.student.entity.Student;
import com.wxy.student.entity.StudentInfo;
import com.wxy.student.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/student")
public class StudentController {

    @Autowired
    private StudentService studentService;



    @GetMapping("/listAll")
    public List<Student> listAll(){
        return studentService.findAll();
    }
    /**
     * 添加学生
     * @param student  参数
     * @return
     */
    @PostMapping("/add")
    public Student save(@RequestBody Student student){
        return studentService.save(student);
    }

    /**
     * 更新学生信息
     * @param student 参数
     * @return
     */

    @PostMapping("/update")
    public  Student update(@RequestBody Student student){
        return studentService.update(student);
    }

    /**
     * 删除学生信息
     * @param id
     */

    @GetMapping("/del/{id}")
    public  String  delete(@PathVariable int id){
        studentService.delete(id);
        return "delete yes";
    }
    /**
     * 班级学生关联查询

     * @return
     */
    @GetMapping("/list")
    public List<StudentInfo> list(){

        return studentService.list();
    }

    /**
     * 根据班级d查询学生
     * @param gradeId
     * @return
     */
    @GetMapping("/findByGradeId/{gradeId}")
    public List<Student> findByGradeId(@PathVariable int gradeId){

        return studentService.findByGradeId(gradeId);
    }

    /**
     * 删除班级
     * @param gradeId
     * @return
     */
    @GetMapping("/delBygradeId/{gradeId}")
    public  String  delBygradeId(@PathVariable int gradeId){
        studentService.deleteByGradeId(gradeId);
        return "delete yes";
    }
}

